//
//  C_MoviePlayerView.m
//  音悦咖
//
//  Created by Best on 15/7/20.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "C_MoviePlayerView.h"

@implementation C_MoviePlayerView


- (void)dealloc
{
    [_buttonView release];
    [_movieController release];
    [super dealloc];
}


- (instancetype)initWithFrame:(CGRect)frame MovieURL:(NSURL *)url
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createMoviePLayerWith:url];
    }
    return self;
    
}


- (void)createMoviePLayerWith:(NSURL *)url
{
    self.backgroundColor = RGBA(239, 234, 231, 0.8);
   
    self.movieController = [[MPMoviePlayerController alloc] initWithContentURL:url];
    self.movieController.controlStyle = MPMovieControlStyleDefault;
    self.movieController.view.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 30);
    [self addSubview:self.movieController.view];
    
    for (NSInteger i = 0; i < 2; i++) {
        CGFloat BW = button.frame.size.width;
        CGFloat LW = countLabel.frame.size.width;
        button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        button.frame = CGRectMake(10 + BW * i + LW * i, self.frame.size.height - 25, (SCREEN_WIDTH - 20) / 8 - 10, 20);
        //[button addTarget:self action:@selector(button:) forControlEvents:(UIControlEventTouchUpInside)];
       BW = button.frame.size.width; //button宽
        button.tag = 3000 + i;
        [self addSubview:button];
        countLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 + BW * (i + 1) + LW * i, self.frame.size.height - 25, (SCREEN_WIDTH - 20) / 8 + 10, 20)];
        //countLabel.text = [NSString stringWithFormat:@"11111%d", i];
        countLabel.tag = 4000 + i;
        countLabel.textColor = RGBA(190, 190, 190, 0.8);
        countLabel.font = [UIFont systemFontOfSize:13];
        [countLabel setTextAlignment:(NSTextAlignmentCenter)];
        [self addSubview:countLabel];
        [countLabel release];
        switch (i) {
            case 0: {
                [button setImage:[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"yes0@2x", @"png")] forState:(UIControlStateNormal)];
                [button setImage:[[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"yes@2x", @"png")] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]forState:(UIControlStateSelected)];
                break;
            }
            case 1: {
                [button setImage:[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"no0@2x", @"png")] forState:(UIControlStateNormal)];
                [button setImage:[[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"no@2x", @"png")] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] forState:(UIControlStateSelected)];
                break;
            }
            case 2: {
                [button setImage:[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"downbutton0@2x", @"png")] forState:(UIControlStateNormal)];
                [button setImage:[[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"downbutton1@2x", @"png")] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] forState:(UIControlStateSelected)];
                countLabel.text = @"下载";
                break;
            }
            case 3: {
                [button setImage:[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"sharebutton0@2x", @"png")] forState:(UIControlStateNormal)];
                [button setImage:[[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"sharebutton1@2x", @"png")] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]forState:(UIControlStateSelected)];
                countLabel.text = @"分享";
                break;
            }
                
            default:
                break;
        }
        
        
        
    }
    
  
    
}


- (void)setModel:(C_MoviesListModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    for (NSInteger i = 0; i < 2; i++) {
        countLabel = (UILabel *)[self viewWithTag:4000 + i];
        switch (i) {
            case 0: {
                countLabel.text = [model.praiseCount description];;
                
                break;
            }
            case 1: {
                countLabel.text = [model.stepCount description];
                
                break;
            }
            default:
                break;
        }
    }
    
    
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
